//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2003 Intrinsyc Europe Ltd.
//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2004 Siemens AG
//
// Version: 1.1.2.5
// Date:    11. Jan. 2006
//////////////////////////////////////////////////////////////////////////////


#pragma once

//
struct LISTVALUEMAP {
    UINT nValue;
    DWORD dwFlag;
};

//
//
struct LISTSTRINGMAP {
    LPCSTR szString;
    DWORD dwFlag;
};


BOOL MatchStringBeginning(const LPCSTR szString, const LPCSTR szMatch, LPCSTR& rszPointer);
BOOL MatchStringEnd(const LPCSTR szString, const LPCSTR szMatch, LPCSTR& rszPointer);
BOOL MatchStringAnywhere(const LPCSTR szString, const LPCSTR szMatch, LPCSTR& rszPointer);
BOOL ParseUInt(const LPCSTR szData, const BOOL fLeadingZerosAllowed, UINT& rnInt, LPCSTR& rszPointer);
BOOL ParseIntAsUInt(const LPCSTR szData, UINT& rnInit, LPCSTR& rszPointer);
BOOL ParseUIntAndVerifyAbove(const LPCSTR szData, const BOOL fLeadingZerosAllowed, UINT nUpperBound, UINT& rnInt, LPCSTR& rszPointer);
BOOL ParseHexUInt(const LPCSTR szData, const BOOL fLeadingZerosAllowed, UINT& rnInt, LPCSTR& rszPointer);
BOOL ParseFixedPoint(const LPCSTR szData, DWORD &rdwFixedPoint, LPCSTR& rszPointer);
BOOL ParseString(const LPCSTR szData, const LPSTR szOut, const UINT cbOut, LPCSTR& rszPointer);
BOOL ParseUnquotedString(const LPCSTR szData, const char chDelimiter, const LPSTR szOut, const UINT cbOut, LPCSTR& rszPointer);
BOOL ParseUnlimitedUnquotedString(const LPCSTR szData, const char chDelimiter, LPSTR& rszOut, UINT& rcbOut, LPCSTR& rszPointer);
BOOL ParseRange(const LPCSTR szData, RILRANGE& rrrRange, LPCSTR& rszPointer);
BOOL ParseRangesFromString(const LPCSTR szData, RILRANGE rgrrRange[], DWORD& rdwNumRanges, DWORD dwMaxRanges, LPCSTR& rszPointer);
BOOL ParseRangeList(const LPCSTR szData, const LISTVALUEMAP* const rglvmMapArray, const UINT nMapArrayLength, DWORD& rdwMask,
                    LPCSTR& rszPointer);
BOOL ParseStringList(const LPCSTR szData, const LISTSTRINGMAP* const rglsmMapArray, const UINT nMapArrayLength, DWORD& rdwMask,
                     LPCSTR& rszPointer);
BOOL ParseRspPrefix(const LPCSTR szData, LPCSTR& rszPointer);
BOOL ParseRspPostfix(const LPCSTR szData, LPCSTR& rszPointer);
BOOL ParseRspParamSeparator(const LPCSTR szData, LPCSTR& rszPointer);
BOOL FindRspPostfix(const LPCSTR szData, LPCSTR& rszPointer);
BOOL ParseGetLocation(const LPCSTR szRsp, UINT& rnLocation, LPCSTR& rszPointer); // in msg.cpp

BOOL FlagFromValue(UINT nValue, const LISTVALUEMAP* const rglsmMapArray, const UINT nMapArrayLength, DWORD& Flag);
BOOL FlagFromString(const LPCSTR szString, const LISTSTRINGMAP* const rglsmMapArray, const UINT nMapArrayLength, DWORD& Flag);

BOOL ValueFromFlag(UINT dwFlag, const LISTVALUEMAP* const rglsmMapArray, const UINT nMapArrayLength, UINT& Value);
BOOL StringFromFlag(UINT dwFlag, const LISTSTRINGMAP* const rglsmMapArray, const UINT nMapArrayLength, LPCSTR& szString);


BOOL ParseUnlimitedString(const LPCSTR szData, LPSTR& rszOut, UINT& rcbOut, LPCSTR& rszPointer);

BOOL EncodedStringSizeToUnicodeStringSize(ENCODING_TYPE enc, size_t cbIn, size_t &cbOut);
BOOL AppendEncodedString(ENCODING_TYPE enc, LPCWSTR pwszIn, LPSTR& pszOut, const LPSTR pszOutEnd, BOOL bAllowUnicode);
BOOL AppendQuotedEncodedString(ENCODING_TYPE enc, LPCWSTR pwszIn, LPSTR& pszOut, const LPSTR pszOutEnd, BOOL bAllowUnicode);
BOOL ParseEncodedString(ENCODING_TYPE enc, LPCSTR pszIn, const LPCSTR pszInEnd, LPWSTR pwszOut, const LPWSTR pwszOutEnd);
BOOL ParseQuotedEncodedString(ENCODING_TYPE enc, LPCSTR& pszIn, LPWSTR pwszOut, const LPWSTR pwszOutEnd);
BOOL ParseUCS2String(const LPCSTR szData, const LPWSTR pwszOut, const UINT cbOut, LPCSTR& rszPointer);

BOOL MatchBytesAnywhere(const BYTE* const pbBytes, const UINT cbBytes, const BYTE* const pbMatch, const UINT cbMatch,
                        const BYTE*& rpbPointer);
BOOL MatchBytesEnd(const BYTE* const pbBytes, const UINT cbBytes, const BYTE* const pbMatch, const UINT cbMatch,
                   const BYTE*& rpbPointer);


